import { login, logout, getInfo } from '@/api/user'
import { getToken, savetToken, delToken } from '@/utils/auth'
import { resetRouter } from '@/router'
import { loginApi } from "@/api/user";

const getDefaultState = () => {
  return {
    token: getToken() || '',
    name: '',
    avatar: '',
    userInfo: {}
  }
}

const state = getDefaultState()

const mutations = {
  serToken(state) {

  },

  removeToken(state) {
    state.token = null
    delToken()
  }
}

const actions = {
  // user login
  async login({ commit }, userInfo) {
    const res = await loginApi({
      postpara: {
        posttype: "saveServer"
      },
      ...userInfo
    })
    console.log(res);

  },



  // user logout
  logout(context) {
    context.commit('removeToken')
  },


}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

